package mop.exception;

/**
 * Exception class for incorrect values
 * 
 * @author	 MOP Team 7
 */
public class IllegalValueException extends Throwable 
{
	
	/**
	 * Initializes an IllegalNameException with the passed value
	 * 
	 * @param value	The value thats incorrect
	 * 
	 * @param reason The reason why the value is incorrect
	 * 
	 * @effect set the value
	 */
	public IllegalValueException(String value,String reason)
	{
		this.setValue(value);	
		this.setReason(reason);
	}
	
	/**
	 * Return a error message that can be used by the gui
	 * @return An error message describing the incorrect value
	 */
	public String toString()
	{
		
		StringBuffer sb = new StringBuffer();
		sb.append("The following value is not a valid one ! ");
		
		if(this.value == null)
			sb.append("NULL");
		else if(this.value.trim().equals(""))
		{
			sb.append("/emptyString");
		}
		else
		{
			sb.append(this.value);
		}
		
		sb.append("\n due to :\n"+this.reason);
		
		return sb.toString();
		
	}
	
	 /**
	  * Set the value
	  * 
	  * @param value	The value that's causing a racket
	  *  
	  * @post The value is set to the passed one
	  */
	 private void setValue(String value) 
	 {
		 this.value = value;
	 }
	
	 /**
	  * Set the reason
	  * 
	  * @param reason --> the reason of suck
	  *  
	  * @post the reason is set to the passed one
	  */
	 private void setReason(String reason) 
	 {
		 this.reason = reason;
	 }
	 
	/**
	 * Weird java demand
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * The value thats causing the problem
	 */
	private String value;
	
	/**
	 * The reason why its causing the problem
	 */
	private String reason;
}
